package com.device.entity;

import javax.persistence.*;
import java.util.UUID;
import static com.device.util.StringUtils.isEquals;

@Entity
@Table(name = "network_configs")
public class NetworkConfig {
    
    @Id
    @Column(name = "id")
    private UUID id;
    
    @Column(name = "device_imei", nullable = false)
    private String deviceImei;
    
    @Column(name = "bound_serial_port", nullable = false)
    private String boundSerialPort = "RS485";
    
    @Column(name = "heartbeat_interval", nullable = false)
    private Integer heartbeatInterval = 60;
    
    @Column(name = "server_address", nullable = false)
    private String serverAddress = "139.159.146.106";
    
    @Column(name = "server_port", nullable = false)
    private Integer serverPort = 1883;
    
    @Column(name = "client_id")
    private String clientId = "";
    
    @Column(name = "username")
    private String username = "";
    
    @Column(name = "password")
    private String password = "";
    
    @Column(name = "subscribe_qos", nullable = false)
    private Integer subscribeQos = 0;
    
    @Column(name = "publish_qos", nullable = false)
    private Integer publishQos = 0;
    
    @Column(name = "subscribe_topic")
    private String subscribeTopic = "";
    
    @Column(name = "publish_topic")
    private String publishTopic = "";
    
    @Column(name = "created_time")
    private Long createdTime;
    
    @Column(name = "updated_time")
    private Long updatedTime;
    
    // Constructors
    public NetworkConfig() {}
    
    public NetworkConfig(String deviceImei) {
        this.id = UUID.randomUUID();
        this.deviceImei = deviceImei;
        this.createdTime = System.currentTimeMillis();
        this.updatedTime = System.currentTimeMillis();
    }

    @Override
    public boolean equals(Object obj) {
        if(null == obj) return false;
        NetworkConfig networkConfig = (NetworkConfig) obj;
        return isEquals(this.serverAddress, networkConfig.getServerAddress()) &&
                isEquals(this.deviceImei, networkConfig.getDeviceImei()) &&
                isEquals(this.boundSerialPort, networkConfig.getBoundSerialPort()) &&
                isEquals(this.password, networkConfig.getPassword()) &&
                isEquals(this.username, networkConfig.getUsername()) &&
                isEquals(this.clientId, networkConfig.getClientId()) &&
                isEquals(this.publishTopic, networkConfig.getPublishTopic()) &&
                isEquals(this.subscribeTopic, networkConfig.getSubscribeTopic()) &&
                this.publishQos.equals(networkConfig.getPublishQos()) &&
                this.subscribeQos.equals(networkConfig.getSubscribeQos()) &&
                this.heartbeatInterval.equals(networkConfig.getHeartbeatInterval()) &&
                this.serverPort.equals(networkConfig.getServerPort());
    }


    // Getters and Setters
    public UUID getId() {
        return id;
    }
    
    public void setId(UUID id) {
        this.id = id;
    }
    
    public String getDeviceImei() {
        return deviceImei;
    }
    
    public void setDeviceImei(String deviceImei) {
        this.deviceImei = deviceImei;
    }
    
    public String getBoundSerialPort() {
        return boundSerialPort;
    }
    
    public void setBoundSerialPort(String boundSerialPort) {
        this.boundSerialPort = boundSerialPort;
    }
    
    public Integer getHeartbeatInterval() {
        return heartbeatInterval;
    }
    
    public void setHeartbeatInterval(Integer heartbeatInterval) {
        this.heartbeatInterval = heartbeatInterval;
    }
    
    public String getServerAddress() {
        return serverAddress;
    }
    
    public void setServerAddress(String serverAddress) {
        this.serverAddress = serverAddress;
    }
    
    public Integer getServerPort() {
        return serverPort;
    }
    
    public void setServerPort(Integer serverPort) {
        this.serverPort = serverPort;
    }
    
    public String getClientId() {
        return clientId;
    }
    
    public void setClientId(String clientId) {
        this.clientId = clientId;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public String getPassword() {
        return password;
    }
    
    public void setPassword(String password) {
        this.password = password;
    }
    
    public Integer getSubscribeQos() {
        return subscribeQos;
    }
    
    public void setSubscribeQos(Integer subscribeQos) {
        this.subscribeQos = subscribeQos;
    }
    
    public Integer getPublishQos() {
        return publishQos;
    }
    
    public void setPublishQos(Integer publishQos) {
        this.publishQos = publishQos;
    }
    
    public String getSubscribeTopic() {
        return subscribeTopic;
    }
    
    public void setSubscribeTopic(String subscribeTopic) {
        this.subscribeTopic = subscribeTopic;
    }
    
    public String getPublishTopic() {
        return publishTopic;
    }
    
    public void setPublishTopic(String publishTopic) {
        this.publishTopic = publishTopic;
    }
    
    public Long getCreatedTime() {
        return createdTime;
    }
    
    public void setCreatedTime(Long createdTime) {
        this.createdTime = createdTime;
    }
    
    public Long getUpdatedTime() {
        return updatedTime;
    }
    
    public void setUpdatedTime(Long updatedTime) {
        this.updatedTime = updatedTime;
    }
} 